function getsankey(){
window.sankey = echarts.init(document.getElementById("sankey"));
sankey.showLoading();

$.ajax({
	type : "post",
	url : $('body').attr('ctxPath') + '/report/visualization/getSankey',
	data : "&startTime=" + M_ECharts_StartTime + "&endTime=" + M_ECharts_EndTime + "&project=" + M_ECharts_Project,
	dataType : "json",
	success : function(result) {
		sankeyOption = {};
		sankeyData = {};
		if (result.state) {
			var nodes = [];
			var nodesTemp= result.data.nodes;
			for (item in nodesTemp) {
				nodes.push({
					name : nodesTemp[item].id,
					show : nodesTemp[item].name
				});
			}
			sankeyData.nodes = nodes;
			var links = [];
			var linksTemp= result.data.links;
			for (item in linksTemp) {
				links.push({
					name : linksTemp[item].id,
					show : linksTemp[item].name,
					source : textShow("id", linksTemp[item].source),
					sourceShow : textShow("text", linksTemp[item].source),
					target : textShow("id", linksTemp[item].target),
					targetShow : textShow("text", linksTemp[item].target),
					value : linksTemp[item].number
				});
			}
			sankeyData.links = links;
			sankeyOption = {
					backgroundColor:'#fff',
			        title: {
			            text: '计划地点流程',
			            left : 0,
			            textStyle : {
							color : '#000',
						}
			        },
			        toolbox: {
			          	 iconStyle: {
			                   normal: {
			                       borderColor: '#ccc'
			                   },
			                   emphasis: {
			                   	 borderColor: '#000'
			                   }
			               },
			              feature: {
			                  restore: {
			                      show: true
			                  },
			                  saveAsImage: {
			                      show: true
			                  }
			              },
			              z: 202
			          },
			        tooltip: {
			            trigger: 'item',
			            triggerOn: 'mousemove',
    					formatter: function(params) {
    						if(params.data.value==null||params.data.value==undefined){
    							return params.data.show;
    						}else{
    							return params.data.sourceShow +" >>> "+ params.data.targetShow +" : "+params.data.value+" 天";
    						}
    					},
			        },
			        series: 
			            {
			                type: 'sankey',
			                layout: 'none',
			                top:"10%",
			    			left:'3%',
			                focusNodeAdjacency:true,
			                label:{
			                	normal:{
			    					color:"#000",
			    					formatter: function(params) {
			    						return "{myStyle|"+params.data.show +"}";
			    					},
			    					rich:{
			    						myStyle:{
			    							fontSize:18,
			    							//padding:[5,0,0,0]
			    						}
			    					}
			    				}
			                },
			                data: sankeyData.nodes,
			                links: sankeyData.links,
			                itemStyle: {
			                    normal: {
			                        borderWidth: 1,
			                        borderColor: '#aaa'
			                    }
			                },
			                lineStyle: {
			                    normal: {
			                    	color: 'source',
			                        curveness: 0.5
			                    }
			                }
			            },
			        data: sankeyData
			    };
			if (sankeyOption && typeof sankeyOption === "object") {
				sankey.setOption(sankeyOption, true);
				sankey.hideLoading();
			}
		} else {
			layer.alert(data.msg);
		}
	},
	error : function() {
		console.log("网络错误，获取计划地点流程数据失败！");
		sankey.hideLoading();
	}
});

}
function textShow(type,text){
	if(type==="id"){
		var arry=text.split("-");
		if(arry.length>=1){
			return  arry[0];
		}
	}else if(type==="text"){
		var arry=text.split("-");
		if(arry.length>=1){
			if(arry.length==2){
				return arry[1];
			}else{
				return  arry[1]+arry[length];
			}
		}
	}
}
